//
//  protocolViewController.m
//  BCVersion
//
//  Created by 吴 崧 on 14-3-6.
//  Copyright (c) 2014年 Jungle. All rights reserved.
//

#import "protocolViewController.h"

@interface protocolViewController ()

@end

@implementation protocolViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        _finishLoadProtocol = NO;
       
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
     _confirmBtn.enabled = NO;
    [BCNetworkClient protocolRegisterSuccess:^(NSString *type, NSString *protocol) {
        [_protocolWebView loadHTMLString:protocol baseURL:nil];
    } failure:^(NSError *error) {
        
    }];
        _protocolWebView.scrollView.delegate = self;
    // Do any additional setup after loading the view from its nib.
}


-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [_protocolWebView stopLoading];
}

-(void)webViewDidFinishLoad:(UIWebView *)webView
{
    self.finishLoadProtocol = YES;
    _confirmBtn.enabled = YES;
}



-(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
    [BCNetworkClient protocolRegisterSuccess:^(NSString *type, NSString *protocol) {
        [webView loadHTMLString:protocol baseURL:nil];
    } failure:^(NSError *error) {
        
    }];

}
- (IBAction)agree:(id)sender {
    if (self.compeletion) {
        self.compeletion(YES);
        self.compeletion = nil;
        [self.navigationController popViewControllerAnimated:YES];
    }
}
- (IBAction)cancel:(id)sender {
    if (self.compeletion) {
        self.compeletion(NO);
        self.compeletion = nil;
    
        [self.navigationController popViewControllerAnimated:YES];
    }

}

-(void)setCompeletion:(ProtocolBlock)compeletion
{
    _compeletion = nil;
    _compeletion = compeletion;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
